home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
shazam11.zip
/
DEMOSE.INC
< prev
next >
Wrap
Text File
|
1991-11-04
|
11KB
|
277 lines
{===================================================================
DATA
===================================================================}
const
FileSpec : string = '*.TXT' ;
{===================================================================
SEARCH
===================================================================}
function CreateFindDialog : PDialog ;
var
D : PDialog ;
Control : PView ;
R : TRect ;
begin
R.Assign ( 0 , 0 , 38 , 12 ) ;
D := New ( PDialog , Init ( R , 'Find' ) ) ;
with D^ do
begin
Options := Options or ofCentered ;
R.Assign ( 3 , 3 , 32 , 4 ) ;
Control := New ( PInputLine , Init ( R , 80 ) ) ;
Insert ( Control ) ;
R.Assign ( 2 , 2 , 15 , 3 ) ;
Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
R.Assign ( 32 , 3 , 35 , 4 ) ;
Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
R.Assign ( 3 , 5 , 35 , 7 ) ;
Insert ( New ( PCheckBoxes , Init ( R ,
NewSItem ( '~C~ase sensitive' ,
NewSItem ( '~W~hole words only' , NIL ) ) ) ) ) ;
R.Assign ( 14 , 9 , 24 , 11 ) ;
Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
Inc ( R.A.X , 12 ) ;
Inc ( R.B.X , 12 ) ;
Insert ( New ( PButton ,
Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
SelectNext ( FALSE ) ;
end ;
CreateFindDialog := D ;
end ;
{===================================================================
REPLACE
===================================================================}
function CreateReplaceDialog : PDialog ;
var
D : PDialog ;
Control : PView ;
R : TRect ;
begin
R.Assign ( 0 , 0 , 40 , 16 ) ;
D := New ( PDialog , Init ( R , 'Replace' ) ) ;
with D^ do
begin
Options := Options or ofCentered ;
R.Assign ( 3 , 3 , 34 , 4 ) ;
Control := New ( PInputLine , Init ( R , 80 ) ) ;
Insert ( Control ) ;
R.Assign ( 2 , 2 , 15 , 3 ) ;
Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
R.Assign ( 34 , 3 , 37 , 4 ) ;
Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
R.Assign ( 3 , 6 , 34 , 7 ) ;
Control := New ( PInputLine , Init ( R , 80 ) ) ;
Insert ( Control ) ;
R.Assign ( 2 , 5 , 12 , 6 ) ;
Insert ( New ( PLabel , Init ( R , '~N~ew text' , Control ) ) ) ;
R.Assign ( 34 , 6 , 37 , 7 ) ;
Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 11 ) ) ) ;
R.Assign ( 3 , 8 , 37 , 12 ) ;
Insert ( New ( PCheckBoxes ,
Init ( R ,
NewSItem ( '~C~ase sensitive' ,
NewSItem ( '~W~hole words only' ,
NewSItem ( '~P~rompt on replace' ,
NewSItem ( '~R~eplace all' , NIL ) ) ) ) ) ) ) ;
R.Assign ( 17 , 13 , 27 , 15 ) ;
Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
R.Assign ( 28 , 13 , 38 , 15 ) ;
Insert ( New ( PButton , Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
SelectNext ( FALSE ) ;
end ;
CreateReplaceDialog := D ;
end ;
{===================================================================
EXECUTE
===================================================================}
function DoEditDialog ( Dialog : integer ; Info : pointer ) : word ; far ;
var
R : TRect ;
T : TPoint ;
begin
case Dialog of
edOutOfMemory :
DoEditDialog := MessageBox ( 'Not enough memory for this operation.' ,
NIL , mfError + mfOkButton ) ;
edReadError :
DoEditDialog := MessageBox ( 'Error reading file %s.' ,
@Info , mfError + mfOkButton ) ;
edWriteError :
DoEditDialog := MessageBox ( 'Error writing file %s.' ,
@Info , mfError + mfOkButton ) ;
edCreateError :
DoEditDialog := MessageBox ( 'Error creating file %s.' ,
@Info , mfError + mfOkButton ) ;
edSaveModify :
DoEditDialog := MessageBox ( '%s has been modified. Save?' ,
@Info , mfInformation + mfYesNoCancel ) ;
edSaveUntitled :
DoEditDialog := MessageBox ( 'Save untitled file?' ,
NIL , mfInformation + mfYesNoCancel ) ;
edSaveAs :
DoEditDialog := ExecDialog ( New ( PFileDialog , Init ( FileSpec ,
'Save file as' , '~N~ame' , fdOkButton , 101 ) ) , Info ) ;
edFind :
DoEditDialog := ExecDialog ( CreateFindDialog , Info ) ;
edSearchFailed :
DoEditDialog := MessageBox ( 'Search string not found.' ,
NIL , mfError + mfOkButton ) ;
edReplace :
DoEditDialog := ExecDialog ( CreateReplaceDialog , Info ) ;
edReplacePrompt :
begin
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Avoid placing the dialog on the same line as the cursor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
R.Assign ( 0 , 1 , 40 , 8 ) ;
R.Move ( ( Desktop^.Size.X - R.B.X ) div 2 , 0 ) ;
Desktop^.MakeGlobal ( R.B , T ) ;
Inc ( T.Y ) ;
if TPoint ( Info ).Y <= T.Y then
R.Move ( 0 , Desktop^.Size.Y - R.B.Y - 2 ) ;
DoEditDialog := MessageBoxRect ( R , 'Replace this occurence?' ,
NIL , mfYesNoCancel + mfInformation ) ;
end ;
end ;
end ;
{===================================================================
Opens a window, with choice of whether visible
===================================================================}
function OpenEditor ( FileName : FNameStr ; Visible : boolean ) : PEditWindow ;
var
P : PView ;
R : TRect ;
begin
DeskTop^.GetExtent ( R ) ;
P := Application^.ValidView (
New ( PEditWindow ,
Init ( R , FileName, wnNoNumber ) ) ) ;
if not Visible then P^.Hide ;
DeskTop^.Insert ( P ) ;
OpenEditor := PEditWindow ( P ) ;
end ;
{===================================================================
Use "FindFirst" to test for file.
Note: Wildcards return FALSE, though there may be matching files.
===================================================================}
function Exist ( Path : string ) : boolean ;
var
SR : SearchRec ;
begin
Exist := FALSE ;
if pos ( '?' , Path ) > 0 then EXIT ;
if pos ( '*' , Path ) > 0 then EXIT ;
FindFirst ( Path , AnyFile , SR ) ;
Exist := DosError = 0 ;
end ;
{===================================================================
Use the "Parse Filename" function of DOS to get a valid drive letter.
This function does not access the drive.
NOTE: Does not correct for "phantom" floppy drives.
===================================================================}
function IsDosDrive ( DriveNum : byte ) : boolean ;
var
FCB : array [ 1 .. 36 ] of byte ;
FileName : array [ 1 .. 3 ] of char ;
R : registers ;
begin
IsDosDrive := FALSE ;
if DriveNum < 1 then EXIT ;
if DriveNum > 26 then EXIT ;
fillchar ( FCB, sizeof ( FCB ), 0 ) ;
FileName := 'x:'#0 ;
FileName [ 1 ] := Chr ( DriveNum + 64 ) ;
with R do
begin
AH := $29 ;
AL := $00 ;
DS := seg ( FileName ) ;
SI := ofs ( FileName ) ;
ES := seg ( FCB ) ;
DI := ofs ( FCB ) ;
MsDos ( R ) ;
if AL = $FF then EXIT ;
end ;
IsDosDrive := TRUE ;
end ;
{===================================================================
DOS 3.1+
IOCTL: Check if block device is remote.
NOTE: DOS returns TRUE, even if the disk number is invalid.
Use program logic or "IsDosDrive" to avoid invalid disks.
===================================================================}
function IsRemote ( DriveNum : byte ) : boolean ;
var
Regs : registers ;
begin
IsRemote := FALSE ;
Regs.AH := $44 ;
Regs.AL := $09 ;
Regs.BL := DriveNum ;
Regs.DX := 0 ;
MsDos ( Regs ) ;
if Regs.Flags and FCarry = 0 then
if ( Regs.DX and $1000 ) <> 0 then { Bit 12, 0=local 1=remote }
IsRemote := TRUE ;
end ;
{===================================================================
Get AUTOEXEC.BAT and CONFIG.SYS via COMSPEC drive
Note: May not be true for networks, if COMSPEC is reset...
===================================================================}
procedure LoadDosIni ;
var
BootDir : string ;
begin
BootDir := copy ( GetEnv ( 'COMSPEC' ) , 1 , 3 ) ;
if IsRemote ( Ord ( BootDir[1] ) - 64 ) then EXIT ;
if exist ( BootDir + 'AUTOEXEC.BAT' ) then
OpenEditor ( BootDir + 'AUTOEXEC.BAT' , TRUE ) ;
if exist ( BootDir + 'CONFIG.SYS' ) then
OpenEditor ( BootDir + 'CONFIG.SYS' , TRUE ) ;
end ;
{===================================================================
Test for Windows 3.0 directory on C: through Z:, but only load local.
===================================================================}
procedure LoadWinIni ;
var
b : byte ;
WinDrive : char ;
begin
for b := 3 to 26 do
begin
if IsDosDrive ( b ) then
if not IsRemote ( b ) then
begin
WinDrive := chr ( b + 64 ) ;
if exist ( WinDrive + ':\WINDOWS\WIN.INI' ) then
begin
OpenEditor ( WinDrive + ':\WINDOWS\WIN.INI' , TRUE ) ;
OpenEditor ( WinDrive + ':\WINDOWS\SYSTEM.INI' , TRUE ) ;
EXIT ;
end ;
end ;
end ;
end ;